package com;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/Welcome")
public class Welcome extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求乱码 设置响应乱码
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        //创建全局变量
        ServletContext servletContext = req.getServletContext();
        Object online = servletContext.getAttribute("online");
        resp.getWriter().write("欢迎你张三<br>"+"当前服务器的在线人数为:"+online);



    }
}
